require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                that: {
                    nickName: "",
                    password: "",
                    mobile: "",
                    email: "",
                    frmRoles: [],
                    status: false,
                    id:""
                }
            }
            , created: function () {
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    toolbar.push({
                        "clas": "layui-icon layui-icon-add-1",
                        "eve": "ADD",
                        "tit": "新增",
                        "fnc": function (data) {
                            dic.openAdd();
                        }
                    });
                    var tool = [];
                    tool.push({
                        "clas": "layui-btn-danger",
                        "eve": "UPDATE",
                        "tit": "修改",
                        "fnc": function (data) {
                            dic.that = data.data;
                            dic.that['status'] = false;
                            dic.that['password']="";
                            dic.that['frmRoles']="";
                            dic.openAdd();
                        }
                    });
                    tool.push({
                        "clas": "layui-btn-danger",
                        "eve": "EUDIT",
                        "tit": "删除",
                        "fnc": function (data) {

                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/oauthuser/AdminUsersController/user/all", [
                        {type: 'checkbox'},
                        {type: 'numbers'},
                        {field: 'id', title: '用户id', minWidth: 120},
                        {field: 'nickName', title: '用户名称', minWidth: 120},
                        {field: 'mobile', title: '手机', minWidth: 120},
                        {field: 'diamond', title: '钻石个数', minWidth: 120},
                        {field: 'gold', title: '金币个数', minWidth: 120},
                        {field: 'amount', title: '消费金额', minWidth: 120},
                        {field: 'balance', title: '当前余额', minWidth: 120},
                        {
                            templet: '<p>{{# layui.each(d.frmRoles, function(index, item){ }} {{ item.name}} {{# }); }}</p>',
                            title: '会员角色',
                            minWidth: 120
                        },
                        {
                            templet: '<p>{{# if(d.status==false){ }} 禁用 {{# } }}{{# if(d.status==true){ }} 启用 {{# } }}</p>',
                            align: 'center',
                            width: 100,
                            title: '状态'
                            , minWidth: 120
                        },
                        {title: '操作', toolbar: '#authoritiesTbBar', align: 'center', width: 120}
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                },
                openAdd: function () {
                    alrYN($("#admins"), function () {
                        var jon = dic.that;
                        jon['status'] = $('input[name="status"]').next().find("em").text();
                        jon['roleCode'] = jon['frmRoles'] instanceof Array ? jon['frmRoles'] : jon['frmRoles'].split(",");
                        var ret = playPost("oauthuser/AdminUsersController/user", "", JSON.stringify(jon));
                        alr(ret.msg);
                    }, function () {

                    }, function () {

                    }, "新增菜单", 1, ["600px", "350px"]);
                }
            }
        });
    })
});